<?php

namespace App\Http\Controllers\Admin;

use App\Repositories\ManagerRepo;
use App\Services\JwtService;
use Illuminate\Http\Request;
use Hash;

class SiteController extends BaseController
{
    public function  login(Request  $request)
    {
        $account = $request->input('account','');
        $password = $request->input('password','');


        $managerRepository = new ManagerRepo();
        $manager = $managerRepository->getManager($account);

        $jwtService = new JwtService();
        if(!$manager) {
            return [
                'code'=>-1,
                'message'=>'账号不存在',
                'password'=>Hash::make('password', [
                'rounds' => 12])
        ];
        }
        if(Hash::check($password,$manager->password)) {
            return  $this->sucRes(200,[
                'token' => $jwtService->createToken($manager->id,'manager')
            ]);
        } else {
            return $this->errRes(-1,"密码错误");
        }
    }
}
